import Page
from Page import Carpark
from Base.Base import Base
from selenium.webdriver.common.by import By


class CarparkDialectSettlementPage(Base):
    """
    猜方言结算界面

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 关闭按钮
        self.settlement_close_btn = (By.XPATH, Carpark.RESOURCE_ID_Dialect.format("iv_close"))

        # 成语接龙标题提示
        self.settlement_title_text = (By.XPATH, Carpark.RESOURCE_ID_Dialect.format("tv_question"))

        # 游戏结束图片
        self.settlement_game_stop_btn = (By.XPATH, Carpark.RESOURCE_ID_Dialect.format("iv_player"))

        # 总分标题
        self.settlement_fraction_title_text = (By.XPATH, Carpark.RESOURCE_ID_Dialect.format("tv_total_record_lab"))

        # 分数
        self.settlement_fraction_text = (By.XPATH, Carpark.RESOURCE_ID_Dialect.format("tv_score"))

        # 击败车主标题
        self.settlement_beat_owner_title_text = (By.XPATH, Carpark.RESOURCE_ID_Dialect.format("tv_beat_record_lab"))

        # 击败车主人数
        self.settlement_beat_owner_number_text = (By.XPATH, Carpark.RESOURCE_ID_Dialect.format("tv_rank"))

        # 继续游戏
        self.settlement_continue_game_btn = (By.XPATH, Carpark.RESOURCE_ID_Dialect.format("tv_again"))

        # 查看排行榜
        self.settlement_view_leaderboard_btn = (By.XPATH, Carpark.RESOURCE_ID_Dialect.format("tv_scan_rank"))

    def click_close(self):
        """
         点击关闭按钮

         :return:None
         """
        self.click_element(self.settlement_close_btn)

    def get_title(self):
        """
        获取结束标题

        :return:获取元素
        """
        return self.find_element_o(self.settlement_title_text)

    def get_game_stop(self, index=5):
        """
        获取游戏结束图片

        :return:获取元素
        """
        self.settlement_game_stop_btn = (By.XPATH, Carpark.idioms_game_stop_icon.format(index))
        return self.find_element_o(self.settlement_game_stop_btn)

    def get_fraction_title(self):
        """
        获取总分标题

        :return:获取元素
        """
        return self.find_element_o(self.settlement_fraction_title_text)

    def get_fraction(self):
        """
        获取总分

        :return:获取元素
        """
        return self.find_element_o(self.settlement_fraction_text)

    def get_beat_owner_title(self):
        """
        获取击败车主标题

        :return:获取元素
        """
        return self.find_element_o(self.settlement_beat_owner_title_text)

    def get_beat_owner_number(self):
        """
        获取击败车主人数

        :return:获取元素
        """
        return self.find_element_o(self.settlement_beat_owner_number_text)

    def click_continue_game(self):
        """
        点击继续游戏按钮

        :return:None
        """
        self.click_element(self.settlement_continue_game_btn)

    def click_view_leaderboard(self):
        """
        点击查看排行榜按钮

        :return:None
        """
        self.click_element(self.settlement_view_leaderboard_btn)

    def is_display_carpark_settlement(self):
        """
        查看是否进入成语接龙游戏结束界面

        :return:
        """
        return self.is_display(self.settlement_game_stop_btn)
